import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:honeypotflutter/modules/account/api/accountApi.dart';
import 'package:honeypotflutter/public/public_get.dart';
import 'package:honeypotflutter/publicBussine/loginInfo/bussine_userInfo.dart';
import 'package:honeypotflutter/public/public_total.dart';

class AccountTransferBalanceLogic extends GetxController {
  UserInfoLogic _userInfoLogic = Get.find<UserInfoLogic>();

  final TextEditingController controller = TextEditingController();

  /*
  * 确认
  * */
  sureAction() async {
    if (controller.text.isEmpty) {
      HLTotal.total("请输入金额");
      return;
    }
    double inputMonry = double.parse(controller.text);
    double wallet = _userInfoLogic.userInfo.wallet ?? 0.00;
    if (wallet <= 0.0) {
      HLTotal.total("可转出金额为0.00元");
      return;
    }
    if (inputMonry > wallet) {
      HLTotal.total("转账金额不能大于账户余额");
      return;
    }

    try {
      HLTotal.progress(status: "提交中...");
      await AccountApi.transferBalance(amount: controller.text, type: 3);
      try {
        await _userInfoLogic.requestUserInfo();
        HLGet.back();
      } catch (error) {
      } finally {
        HLTotal.dismiss();
      }
    } catch (error) {
      HLTotal.dismiss();
    }
  }
}
